using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class Menus : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void dsMenus_SelectData(object sender, Acms.DataControls.SelectEventArgs<Acms.Bll.Menu> e)
    {
        e.SetData(Acms.Bll.Menu.GetAll());
    }

    protected void dsMenus_UpdatingData(object sender, Acms.DataControls.UpdatingDataEventArgs<Acms.Bll.Menu> e)
    {
        if (e.Action == Acms.DataControls.UpdateAction.Insert)
        {
            e.Item.SiteId = AcmsSite.Id;
        }
    }

    protected void dsPosts_SelectData(object sender, Acms.DataControls.SelectEventArgs<Acms.Bll.Post> e)
    {
        List<Acms.Bll.Post> tmp = new List<Acms.Bll.Post>();
        Acms.Bll.Post post = Acms.Bll.Post.GetTopLevelBySiteId(AcmsSite.Id);
        tmp.Add(post);
        AddChildren(post, tmp);
        e.SetData(tmp);
    }

    private void AddChildren(Acms.Bll.Post post, List<Acms.Bll.Post> posts)
    {
        List<Acms.Bll.Post> tmp = Acms.Bll.Post.GetAllByParentId(post.Id);
        foreach (Acms.Bll.Post p in tmp)
        {
            posts.Add(p);
            AddChildren(p, posts);
        }
    }
}
